﻿using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.Charts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dll_DynamicDataDisplay.ViewModels.DispElement
{
    /// <summary>
    /// 图表元素-竖线类
    /// </summary>
    [Serializable]
    public class Vm_Element_VerLine : Vm_Element
    {
        #region NotifyProperty

        /// <summary>
        /// 竖线的横坐标值
        /// </summary>
        public double Value
        {
            get { return _Value; }
            set
            {
                if (_Value != value)
                {
                    _Value = value;
                    this.OnPropertyChanged("Value");

                    //重绘图表
                    this.ReDraw();
                }
            }
        }
        private double _Value = 0.0;

        #endregion

        /// <summary>
        /// 连接到ChartPlotter对象
        /// </summary>
        /// <param name="Plotter"></param>
        public override void ChartPlotter_Attach(ChartPlotter Plotter)
        {
            base.ChartPlotter_Attach(Plotter);

            this.line_ver = new VerticalLine();
            this.line_ver.Stroke = this.Stroke_Brush;
            this.line_ver.StrokeThickness = this.Stroke_Thickness;

            Plotter.Children.Add(this.line_ver);

            ReDraw();
        }

        /// <summary>
        /// 断开与ChartPlotter的连接
        /// </summary>
        public override void ChartPlotter_Detach()
        {
            if (this.line_ver == null)
                return;

            Plotter.Children.Remove(this.line_ver);

            base.ChartPlotter_Detach();
        }

        /// <summary>
        /// 刷新图表数据
        /// </summary>
        public override void ReDraw()
        {
            if (this.Plotter == null)
                return;

            this.line_ver.Value = this.Value;
        }

        #region Private

        /// <summary>
        /// 竖线对象
        /// </summary>
        [NonSerialized]
        VerticalLine line_ver;

        #endregion
    }
}
